#include "Options.h"
#include "Menu.h"
using namespace cocos2d;
bool Music_Enable = true;

CCScene* Options::scene()
{
	CCScene *scene = NULL;
	do
	{
		scene = CCScene::create();
		CC_BREAK_IF(!scene);
		Options *layer = Options::create();
		CC_BREAK_IF(!layer);
		scene->addChild(layer);
	} while (0);
	return scene;
}

bool Options::init()
{
	bool bRet = false;
	do{
		CC_BREAK_IF(!CCLayer::init());

		CCSize size = CCDirector::sharedDirector()->getWinSize();
		CCSprite *mu = CCSprite::create("settings.jpg");
		CC_BREAK_IF(!mu);
		mu->setPosition(ccp(size.width/2,size.height/2));
		this->addChild(mu,0);

		pMusicON = CCLabelTTF::create("MUSIC ON","Segoe Marker",24);
		pMusicOFF = CCLabelTTF::create("MUSIC OFF","Segoe Marker",24);
		pBack = CCLabelTTF::create("BACK","Segoe Marker",24);

		pMusicONItem = CCMenuItemLabel::create(pMusicON,this,menu_selector(Options::setMusicEnable));
		pMusicONItem->setPosition(ccp(size.width/2,size.height/2 - 10));

		Settings = CCMenu::create(pMusicONItem,NULL);
		Settings->setPosition(CCPointZero);
		this->addChild(Settings,1);

		pBackItem = CCMenuItemLabel::create(pBack,this,menu_selector(Options::goBack));
		pBackItem->setPosition(ccp(size.width/2,size.height/2 - 90));

		CCMenu *backs = CCMenu::create(pBackItem,NULL);
		backs->setPosition(CCPointZero);
		this->addChild(backs,1);
		
		bRet = true;
	}while(0);
	return bRet;
}


void Options::goBack(CCObject *pSender)
{
	CCScene *s = Menu::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFadeDown::create(1,s));
}

void Options::setMusicEnable(CCObject *p)
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	pMusicON = CCLabelTTF::create("MUSIC ON","Segoe Marker",24);
	pMusicOFF = CCLabelTTF::create("MUSIC OFF","Segoe Marker",24);
	if(!Music_Enable)
	{
		this->removeChild(Settings);
		CCMenuItemLabel *pMusicONItem = CCMenuItemLabel::create(pMusicON,this,menu_selector(Options::setMusicEnable));
		pMusicONItem->setPosition(ccp(size.width/2,size.height/2 - 10));
		Settings = CCMenu::create(pMusicONItem,NULL);
		Settings->setPosition(CCPointZero);
		this->addChild(Settings,1);
		Music_Enable = true;
	}
	else
	{
		this->removeChild(Settings);
	//	this->removeChild(pBackItem,true);
		CCMenuItemLabel *pMusicOFFItem = CCMenuItemLabel::create(pMusicOFF,this,menu_selector(Options::setMusicEnable));
		pMusicOFFItem->setPosition(ccp(size.width/2,size.height/2 - 10));
		Settings = CCMenu::create(pMusicOFFItem,NULL);
		Settings->setPosition(CCPointZero);
		this->addChild(Settings,1);
		Music_Enable = false;
	}
	
}
		